/**
 * 移动终端跳转规则
 */
function __go_pad(data) {

    if (data.code == 200) {
        window.location.href = data.url;
    }
}

(function() {
    if (/iPad|Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent.toLowerCase())) {
        (function() {
            var url = "http://w.huanqiu.com/apps/wap2w/go_pad.php";
            var script = document.createElement('script');
            script.setAttribute('src', url);
            document.getElementsByTagName('head')[0].appendChild(script);
        })()
    }

})(window);





//////////////////////
function Section(opt) {
	this.o           = $.extend({
						title    :"环球网",
						link     :"http://www.huanqiu.com/",
						atlas    :"#atlas",      //图片列
						stride   :8,
						picIndex :6
					},opt);
	var doc          = document,
		styleElement = doc.createElement('style');
		
	$(styleElement).attr("type","text/css"); 
	$("head").eq(0).append($(styleElement));
	if(styleElement.styleSheet){ //ie 
		styleElement.styleSheet.cssText += this.cssCode; 
	}else if(doc.getBoxObjectFor){ 
		styleElement.innerHTML += this.cssCode; //火狐
	}else{
		styleElement.appendChild(doc.createTextNode(this.cssCode));
	}
	
	if(typeof this.o.atlas=="string") {
		this.picL = $(this.o.atlas).find("img");
		if(this.picL.length) {
			this.picL.each(function() {
				var _this = $(this);
				this.src = _this.attr("src");  //小图地址
				this.rel = _this.attr("rel");	//中图地址
				this.des = _this.next("span").eq(0).text(); //描述地址
			});
			$(this.o.atlas).html("");
		}
	}else {
		this.picL = this.o.atlas;  // [{'src':'','rel':'','des':''},{'src':'','rel':'','des':''}];
	}
	if(!this.picL.length) return;
	this.writeDoc();
}

Section.prototype = {
	writeDoc:function() {
		var $box    = $(document.createElement("div")),
			liArr   = [];
		$box.addClass("imgArray").html(this.htmCode).appendTo($(this.o.atlas)); //临时
		$('a[bosszone="title"]').attr('href',this.o.link).html(this.o.title); //title
		this.picL.each(function(i) {
			liArr.push('<li><div><a href="javascript:void(0);" class="" bosszone="select" onfocus="this.blur()"><img rel="'+this.rel+'" src="'+this.src+'" bosszone="pic" /><span>'+this.des+'</span><span class="rigNum">'+(i+1)+'</span></a></div><div class="mask"></div></li>');
		});
		$("#tatolNum").text(this.picL.length);
		this.ul         = $('ul[bosszone="gqList"]');
		this.scrollBox  = $('div[bosszone="scrollBox"]');
		this.scrollBar  = $('div[bosszone="scrollBar"]');
		this.$picB      = $('img[bosszone="bigPic"]');
		this.gqUp       = $('a[bosszone="gqUp"]');
		this.gqDown     = $('a[bosszone="gqDown"]');
		$(this.o.atlas).show();
		this.ul.html(liArr.join(""));
		this.SmallWarp  = $("#SmallWarp");
		this.picWrap    = $("#picWrap");
		this.des        = $('p[bosszone="des"]');
		this.curNum     = $("#curNum");
		this.mainA      = $("#Main-A");
		this.sW         = this.SmallWarp.width();
		this.$mask      = $('ul[bosszone="gqList"]').find(".mask");
		this.liWidth    = this.ul.find('li').eq(0).innerWidth()+2,
		this.ulW        = this.liWidth*this.picL.length,
		this.scrollBoxW = this.scrollBox.width(),
		this.pp         = this.ulW/this.scrollBoxW;
		this.scrollBarW = Math.ceil(this.scrollBoxW/this.pp);
		this.ul.width(this.ulW);
		this.scrollBar.width(this.scrollBarW);
		this.a          = this.scrollBoxW-this.scrollBarW;
		this.c          = this.ulW-this.sW;
		this.sPic();
		this.moveFn();
		this.showFn();
	},
	sPic:function() {
		var copy_this = this;
		this.ul.find('img[bosszone="pic"]').each(function(i) {
			var _this  = $(this);
			copy_this.loadOk(this.src,function() {
				var w = _this.width(),
				    h = _this.height();
				if(w>=h) {
					_this.height(80);
					w = _this.width();
					w>100&&_this.css("margin-left",-Math.ceil((w-100)/2));
				}else {
					_this.width(100);
					h = _this.height();
					h>80&&_this.css("margin-top",-Math.ceil(h*0.15));
				}
			});
			_this.click(function() {
				copy_this.o.picIndex = i+1;
				copy_this.showFn();
			});
		});
		if(this.picL.length<=5) {
			this.gqUp.hide();
			this.gqDown.hide();
			this.scrollBox.hide();
			this.scrollBar.hide();
		}else {
			this.fast = null;
			this.gqUp.mousedown(function() {
				$(document.body).bind("selectstart",copy_this.selectstart);
				copy_this.fastFn("left");
			}).mouseup(function() {
				$(document.body).unbind("selectstart",copy_this.selectstart);
				copy_this.fast&&clearTimeout(copy_this.fast);
			});
			this.gqDown.mousedown(function() {
				$(document.body).bind("selectstart",copy_this.selectstart);
				copy_this.fastFn("right");
			}).mouseup(function() {
				$(document.body).unbind("selectstart",copy_this.selectstart);
				copy_this.fast&&clearTimeout(copy_this.fast);
			});
		}
		this.picWrap.mousemove(function(event) {
			var pos = copy_this.mouseP(arguments[0]);
			pos.x-copy_this.picWrap.offset().left>copy_this.picWrap.width()/2?copy_this.picWrap.addClass("r").removeClass("l"):copy_this.picWrap.addClass("l").removeClass("r");
		}).click(function() {
			if(copy_this.picWrap.hasClass("r")) {
				if(copy_this.o.picIndex<copy_this.picL.length) copy_this.o.picIndex++;
				else copy_this.o.picIndex = 1;
			}else {
				if(copy_this.o.picIndex>1) copy_this.o.picIndex--;
				else copy_this.o.picIndex = copy_this.picL.length;
			}
			copy_this.showFn();
		});
	},
	fastFn:function() {
		var l = parseInt(this.scrollBar.css("left")),
			v = arguments[0];
		l = v=="left"?l-this.o.stride:l+this.o.stride;
		if(l<0) {
			l = 0;
			this.fast&&clearTimeout(this.fast);
		}else if(l>this.scrollBoxW-this.scrollBarW) {
			l = this.scrollBoxW-this.scrollBarW;
			this.fast&&clearTimeout(this.fast);
		}
		this.scrollFn(l,this.a,this.c,false);
		this.fast = setTimeout((function(t) {return function() {t.fastFn.call(t,v);};})(this),30);
	},
	moveFn:function() {
		this.scrollBar.mousedown((function(t) {return function() {t.mD.call(t);};})(this));
		$(document.body).mouseup((function(t) {return function() {t.mU.call(t);};})(this));
	},
	mD:function() {
		var pos = this.mouseP(arguments[0]),
			s   = pos.x,
			l   = parseInt(this.scrollBar.css("left"));
		$(document.body).bind("selectstart",this.selectstart);
		$(document.body).bind("mousemove",(function(t) {
			return function() {
				t.scrFn.apply(t,[arguments[0],s,l]);
			};
		})(this));
	},
	mU:function() {
		$(document.body).unbind("mousemove");
		$(document.body).unbind("selectstart",this.selectstart);
	},
	scrFn:function() {
		var pos = this.mouseP(arguments[0]),
			v   = pos.x-arguments[1]+arguments[2];
		if(v<0) {
			v = 0;
		}else if(v>this.scrollBoxW-this.scrollBarW) {
			v = this.scrollBoxW-this.scrollBarW;
		}
		this.scrollFn(v,this.a,this.c,false);
	},
	selectstart:function() {
		return false;
	},
	showFn:function() {
		// $(window).scrollTop($(this.o.atlas).offset().top);
		var n     = this.o.picIndex - 1,
			obj   = this.picL[n],
			des   = obj.des,
			rel   = obj.rel;
		this.$picB.hide();
		this.des.text(des);
		this.curNum.text(this.o.picIndex);
		this.$mask.hide().eq(n).show();
		$('a[bosszone="select"]').removeClass("select").eq(n).addClass("select");
		this.loadOk(rel,function() {
			this.$picB.attr("src",rel);
			this.picWrap.find("a").attr("href",rel);
			setTimeout(function(t) {return function() {
				t.$picB.fadeIn(200);
				var h = t.$picB.innerHeight();
				t.picWrap.height(h);
				t.mainA.height(h);
			}}(this),100);
			
		});
		this.cliFn(n);
	},
	cliFn:function(n) {
		var fri  = Math.floor(this.sW/this.liWidth/2),
			last = this.picL.length-1-fri,
			v    = (n-fri)*this.liWidth,
			pol  = last*this.liWidth-fri*this.liWidth,
			l    = this.ulW-this.sW,
			s    = this.scrollBox.width()-this.scrollBar.width();
		if(v>=0&&v<=pol) {
			this.scrollFn(v,l,s,true);
		}else if(v<0){
			this.scrollFn(0,l,s,true);
		}else {
			this.scrollFn(pol,l,s,true);
		}
	},
	scrollFn:function(v,l,s,t) {
		var p = Math.round(v/l*100)/100;
		if(t) {
			this.SmallWarp.animate({scrollLeft:v},300);
			this.scrollBar.animate({"left":Math.round(s*p)},300)
		}else {
			
			this.scrollBar.css("left",v);
			this.SmallWarp.scrollLeft(Math.round(s*p));
		}
	},
	loadOk:function(l,callback) {  // load pic
		var picObj = new Image();
		picObj.src = l;
		picObj.complete?callback.call(this):(picObj.onload = function(t) {return function() {return callback.call(t)}}(this));
	},
	mouseP:function() {
		var e       = arguments[0] || window.event,
			scrollX = document.documentElement.scrollLeft || document.body.scrollLeft,
			scrollY = document.documentElement.scrollTop || document.body.scrollTop,
			x       = e.pageX || e.clientX + scrollX,
			y       = e.pageY || e.clientY + scrollY;
			
		return {x:x,y:y};
	},
	htmCode:'<div class="title"><h1><a href="#" bosszone="title" target="_blank"></a></h1></div><div class="section"><div id="Main-A" style="width: 600px; height: 301px;"><div id="picWrap" onselectstart="return false" class="cursor-left" bosszone="gqLeft" style="position: absolute; left: 25px; top: 9px; width: 550px; height: 300px;text-align:center;"><img bosszone="bigPic" src="" style="opacity: 1;width:auto;height:auto;"><a href="" target="_blank" class="slideBtn" bosszone="gqYT" id="slideBtn" hidefocus="true"></a></div><div id="InfoWrap"><div id="Info" style="background: rgba(245, 245, 245, 0.6);"><div id="infoNum" style="top: 15px;"><span id="curNum">--</span><span class="numLine"></span><span id="tatolNum">--</span></div><div id="infoTxtWrap" style="height: 80px;"><div  style="height: 64px;"><div id="infoTxt" style="margin-top: 0px;"><p bosszone="des"></p></div></div><div id="time_source"><span class="shareSummary">分享 <div class="bdsharebuttonbox"><a href="#" class="bds_more" data-cmd="more"></a><a href="#" class="bds_qzone" data-cmd="qzone" title="分享到QQ空间"></a><a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博"></a><a href="#" class="bds_tqq" data-cmd="tqq" title="分享到腾讯微博"></a><a href="#" class="bds_renren" data-cmd="renren" title="分享到人人网"></a><a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信"></a></div></span></div><div id="t_scroll_wrap"><div id="t_scroll" style="top: 0px;"></div></div></div><div id="closedTxt" class="closedTxt t_close">隐藏图注<i></i></div></div></div><div id="mouseMask" unselectable="on" class="cursor-left" bosszone="gqLeft"></div></div><div id="Main-C"><div class="smallPic"><a href="javascript:;;" onfocus="this.blur()" class="sBtn sBtnLeft" id="goleft" hidefocus="true" bosszone="gqUp"></a><div class="SmallWarp" id="SmallWarp" style="width: 540px;"><ul bosszone="gqList"></ul></div><a href="javascript:;;" onfocus="this.blur()" class="sBtn sBtnRight" id="goright" hidefocus="true" bosszone="gqDown"></a></div><div class="scrollDiv" bosszone="scrollBox"><div class="scrollBar" style="left:0px;" bosszone="scrollBar"><span></span></div></div></div></div>',
	cssCode:'.sBtnLeft ,.sBtnRight{background:url(http://himg2.huanqiu.com/statics/hq2013/images/section/article.png) no-repeat}.shareSummary{background-position:8px -123px;width:40px;height:15px;margin:3px 8px 0 8px;text-indent:13px;padding:1px 5px 0 15px;border-left:#ededed 1px solid;position:relative;overflow:hidden;display:inline-block;float:left}.shareSummary em{background-position:0 -97px}.shareSummary .bdsharebuttonbox{display:block;width:45px;height:30px;overflow:hidden;position:absolute;top:-10px;right:0}.shareSummary .bdsharebuttonbox a.bds_more{background:none;width:75px;margin:6px 0 6px 0}.imgArray{display:block;width:600px;background:#f5f5f5;padding:19px 0 0;border-top:#808080 3px solid;margin:30px 0}.title{display:block;position:relative;margin:0 25px;z-index:4}.title h1{color:#06346f !important;font:18px "Microsoft YaHei", arial;line-height:26px;margin:0 !important;padding:0 0 10px;}.title h1 a{font:18px "Microsoft YaHei", arial}#Main-A{height:100%;margin:0 auto;position:relative;background:url(http://mat1.gtimg.com/news/hd2009fin/ajax-loader.gif) no-repeat center center;padding:0 0 100px;z-index:3}#InfoWrap{position:absolute;width:100%;bottom:0;z-index:6}#Info{display:block;width:550px;background:rgba(245,245,245,0.6);filter:progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr=#B2f5f5f5,endColorstr=#B2f5f5f5);*zoom:1;text-align:left;padding-top:5px;margin:0 auto;position:relative}#infoNum{position:absolute;left:0;top:15px;width:90px;font-family:Georgia,tahoma;font-size:20px;color:#757575;text-align:center}#curNum{font-size:24px;color:#379be9;position:absolute;left:0;top:-3px;z-index:100}#tatolNum{font-size:14px;color:#8c8c8c;position:absolute;left:24px;top:30px;z-index:100}.numLine{background:url(http://himg2.huanqiu.com/statics/hq2013/images/section/numLine.png) no-repeat;display:block;width:45px;height:45px;position:absolute;left:0;top:0;z-index:1}#infoTxtWrap{position:relative;margin:0 75px 0 83px;width:470px;height:80px;padding:6px 0 0 0;overflow:hidden}#infoCon{position:relative;height:52px;overflow:hidden}#infoTxt{font-size:12px;line-height:20px;color:#666}#time_source{font-size:12px;line-height:16px;color:#999;text-align:right;padding-top:6px;margin-right:-5px;position:absolute;bottom:5px;right:5px}#time_source span{margin:0 5px}#mouseMask{width:98%;height:100%;position:absolute;top:0;left:0;z-index:5;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;user-select:none;background:url(about:blank)\9}.btnn{position:absolute;top:35%;visibility:hidden;z-index:9}.btnn a{display:block;width:31px;height:61px}.btnLeft{left:110px}.btnRight{right:110px}.btnLeft a{background-position:-189px -404px}.btnRight a{background-position:-270px -404px}.slideBtn{position:absolute;right:0;top:0;width:32px;height:32px;background:url(http://mat1.gtimg.com/www/hd/images/slide_1.png) no-repeat;_background-image:none;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="../../../../../mat1.gtimg.com/www/hd/images/slide_1.png"/*tpa=http://mat1.gtimg.com/www/hd/images/slide_1.png*/, sizingMethod="scale")}.slideBtn:hover{background:url(http://mat1.gtimg.com/www/hd/images/slide_hover_1.png) no-repeat;_background:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="../../../../../mat1.gtimg.com/www/hd/images/slide_hover_1.png"/*tpa=http://mat1.gtimg.com/www/hd/images/slide_hover_1.png*/, sizingMethod="scale")}.closedTxt{width:64px;height:21px;overflow:hidden;line-height:22px;border-radius:2px;padding-left:7px;border-style:solid;border-width:1px;position:absolute;top:-18px;right:80px;cursor:pointer;border-color:#dfdfdf;background-color:#fff;color:#000;display:none}.closedTxt:hover{border-color:#4785bf;background-color:#47a8f4;color:#fff}.closedTxt i{position:absolute;right:6px;width:0;height:0;font-size:0;line-height:0;border-width:4px;border-style:solid;border-color:#379be9 #fff #fff;top:8px}.closedTxt:hover i{border-color:#fff #47a8f4 #47a8f4;top:8px}#t_scroll_wrap{width:1px;height:500px;position:absolute;right:3px;top:6px;background:#a5a5a5;display:none}#t_scroll{width:5px;height:200px;background:#379be9;position:absolute;cursor:pointer;top:0;left:-2px;z-index:3;border-radius:7px}#mouseMask{width:98%;height:100%;position:absolute;top:0;left:0;z-index:5;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;user-select:none;background:url(about:blank)\9}#picWrap{width:0;height:0;overflow:hidden;z-index:6;_background:#000;-moz-user-select:none}#picWrap img {max-width:550px;max-height:600px;}#bigPic{width:100%;height:100%;background:#000}#Main-C{height:150px;position:relative}.smallPic-wrap{position:absolute;right:0}.smallPic{overflow:hidden;font-size:12px;color:#fff;position:relative;padding:0 30px;left:0;*zoom:1}.sBtn{position:absolute;width:30px;height:50px;z-index:3;top:27px}.sBtnLeft{left:0}.sBtnRight{right:0;background-position:-40px 0}.sBtnLeft:hover{left:0;background-position:-80px 0}.sBtnRight:hover{right:0;background-position:-120px 0}.smallPic .SmallWarp{height:99px;padding:6px 0 0 0;overflow:hidden;position:relative;left:0}.smallPic .SmallWarp a.mask{position:absolute;width:130px;height:89px;overflow:hidden;z-index:1;left:4px;background:#fc7203}.smallPic .SmallWarp ul{position:absolute;z-index:2;left:0}.smallPic .SmallWarp li{float:left;width:106px;height:86px;position:relative;text-align:center;margin:0 0 0 2px;overflow:hidden}.smallPic .SmallWarp li .mask{display:none;width:106px;height:86px;position:absolute;left:0;top:-3px;z-index:1;background:#fc7203}.smallPic .SmallWarp a.mask ,.smallPic .SmallWarp li .mask .rigNum{background:#fc7203}.smallPic .SmallWarp li div{width:106px;height:86px;position:absolute;left:0;top:0;z-index:3;overflow:hidden;margin-top:3px}.smallPic .SmallWarp li div a{display:inline-block;text-align:center;height:80px;width:100px;margin:0 auto;overflow:hidden;cursor:pointer;position:relative}.smallPic .SmallWarp li a:hover{text-decoration:none}.smallPic .SmallWarp li a span{display:none}.smallPic .SmallWarp .rigNum ,.smallPic .SmallWarp .select .rigNum{display:block;background:#4d4d4d;width:18px;height:18px;line-height:18px;font-family:Arial;font-size:12px;text-align:center;color:#fff;position:absolute;right:0;bottom:0}.smallPic .SmallWarp .select .rigNum{background:#fc7203;right:-3px;bottom:-3px}#mask{width:100%;height:100%;position:absolute;top:0;left:0;z-index:9;background:#fff;display:none}#maskBg{position:absolute;width:100%;height:100%;z-index:1000;top:0;left:0;background:#000;overflow:hidden;font-size:14px}#maskBody{position:absolute;width:100%;height:100%;z-index:1001;left:0;top:0;overflow:hidden;font-family:"simSun"}#maskBody a{outline:0}.l{cursor:url("http://himg2.huanqiu.com/statics/hq2013/images/ico/l.ico"),auto}.r{cursor:url("http://himg2.huanqiu.com/statics/hq2013/images/ico/r.ico"),auto}.scrollDiv{display:block;width:528px;height:2px;margin:0 0 0 37px;border-top:#dadada 2px solid;-moz-user-select:none;-khtml-user-select:none;user-select:none}.scrollBar{width:40px;height:10px;position:relative;background:#b6b6b6;cursor:pointer;-moz-user-select:none;-khtml-user-select:none;user-select:none;margin:-6px 0 0}.scrollBar:hover {background:#5fc4e8;}'
};




